<?php
	/**
	 * 
	 */
	class MyaccountAction extends CommonAction {
		public function index(){
			$model = M('User');
			$info = $model->where("id='".$_SESSION['authId']."'")->find();
			$this->assign("info",$info);
			$this->display();
		}
		
		public function info(){
			$model = M('UserInfo');
			$info = $model->where("uid='".$_SESSION['authId']."'")->find();
			if (empty($info)){
				$data['uid'] = $_SESSION['authId'];
				$model->add($data);
			}
			$this->assign("info",$info);
			$this->display();
		}
		
		public function update(){
			$user_model = D('User');
			switch ($_GET['type']) {
				case 'basic':
					if ($_POST['basic']){
						$user_model->where("id='".$_SESSION['authId']."'")->save($_POST);
						$this->assign("jumpUrl",$_SERVER['HTTP_REFERER']);
						$this->success('修改成功');
					}
					break;
				
				case 'info':
					$info_model = D('UserInfo');
					if ($_POST['info']){
						$info_model->where("uid='".$_SESSION['authId']."'")->save($_POST);
						$this->assign("jumpUrl",$_SERVER['HTTP_REFERER']);
						$this->success('修改成功');
					}
					break;
					
				case 'password':
					if ($_POST['setpassword']){
						$_POST['password'] = trim($_POST['password']);
						$_POST['repassword'] = trim($_POST['repassword']);
						if ($_POST['password'] == $_POST['repassword']){
							$user_model->where("id='".$_SESSION['authId']."'")->setField('password',md5($_POST['password']));
							$this->assign("jumpUrl",$_SERVER['HTTP_REFERER']);
							$this->success('修改成功');
						}else{
							$this->error('两次密码不一致');
						}
					}
					break;
			}
		}
		
		/*public function _before_info(){
			$model = M('role');
			$list = $model->where("pid='0'")->select();
			
			$html = '';
			foreach ($list as $key => $val) {
				$html .= '<option value="'.$val['id'].'">'.$val['name'].'</option>';
				$html .= $this->getOptionRole($model, $val['id'], '├──');
			}
			$this->assign("option",$html);
		}
		
		
		private function getOptionRole($model,$pid,$step){
			$list = $model->where("pid='".$pid."'")->select();
			$html = '';
			if (!empty($list)){
				foreach ($list as $key=>$val){
					$html .= '<option value="'.$val['id'].'">'.$step.$val['name'].'</option>';
					$html .= $this->getOptionRole($model, $val['id'], '├──'.$step);
				}
			}
			return $html;
		}*/
		
	}
	
?>